import java.util.ArrayList;

/**
Problem 5
30 November 2001

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
 */

/**
 * @author Hitec
 *
 */
public class Program {
	
	private static final int MAX_NUMBER = 20;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		ArrayList<Integer> primeFactors = new ArrayList<Integer>();

		// Get prime factors of all number until the max number
		for(int index = 2; index <= MAX_NUMBER; index++){
			for(int factor : Primes.primeFactors(index)){
				if(!primeFactors.contains(factor)){
					primeFactors.add(factor);
				}
			}
		}
		
		// Determine max powers of all factors less than max number
		int smallestDivisibleNumber = 1;
		
		for(int factor : primeFactors){
			smallestDivisibleNumber *= determineHighestPower(factor);
		}
		
		System.out.println(smallestDivisibleNumber);
	}

	private static int determineHighestPower(int factor) {
		int highestPower = factor;
		
		for(int power = 1; power <= MAX_NUMBER; power++){
			if(Math.pow(factor, power) > MAX_NUMBER){
				break;
			}
			else {
				highestPower = (int) Math.pow(factor, power); 
			}
		}
		
		return highestPower;
	}

}
